package com.s3.khospitalds.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.s3.khospitalds.common.ResponseEntity;
import com.s3.khospitalds.entity.Doctor;
import com.s3.khospitalds.entity.TableShift;
import com.s3.khospitalds.mapper.TableShiftMapper;
import com.s3.khospitalds.service.TableShiftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: xw
 * @CreateTime: 2025/2/20
 * @Description: 护士轮班类
 * @Version: 1.0
 */
@Service
public class TableShiftServiceImpl extends ServiceImpl<TableShiftMapper, TableShift> implements TableShiftService {
    @Autowired
    private TableShiftServiceImpl tableShiftService;
    @Autowired
    private TableShiftMapper tableShiftMapper;

    @Override
    public ResponseEntity selectAll(int pageNum, int pageSize, String searchDepartment, String searchName, String searchTimes) {
        ResponseEntity responseEntity = new ResponseEntity();
        //开启分页
        PageHelper.startPage(pageNum,pageSize);
        //模糊查询
        QueryWrapper queryWrapper = new QueryWrapper<>();
        if (searchDepartment!=""){
            queryWrapper.eq("department",searchDepartment);
        }
        if (searchTimes!="") {
            queryWrapper.eq("time", searchTimes);
        }
        queryWrapper.like("name",searchName);
        //使用分页查询
        List<Doctor> tableShift = tableShiftService.list(queryWrapper);
        //创建分页的对象
        PageInfo<Doctor> pageInfo = new PageInfo<>(tableShift);
        //设置响应对象的值
        responseEntity.setCount((int) pageInfo.getTotal());
        //设置响应对象的行数据
        responseEntity.setData(pageInfo.getList());
        return responseEntity;
    }

    @Override
    public int insert(TableShift tableShift) {
        return tableShiftMapper.insert(tableShift);
    }

    @Override
    public int update(TableShift tableShift) {
        return tableShiftMapper.update(tableShift);
    }

    @Override
    public int delete(int id) {
        return tableShiftMapper.delete(id);
    }
}
